/*
 * Copyright (c) 2018-2999 广州亚米信息科技有限公司 All rights reserved.
 *
 * https://www.gz-yami.com/
 *
 * 未经允许，不可做商业用途！
 *
 * 版权所有，侵权必究！
 */

package com.yami.shop.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yami.shop.bean.model.Ercode;
import com.yami.shop.bean.model.IndexImg;
import com.yami.shop.dao.ErcodeMapper;
import com.yami.shop.dao.IndexImgMapper;
import com.yami.shop.service.ErcodeService;
import com.yami.shop.service.IndexImgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * @author lgh on 2018/11/26.
 */
@Service
public class ErcodeServiceImpl extends ServiceImpl<ErcodeMapper, Ercode> implements ErcodeService {

    @Autowired
    private ErcodeMapper ercodeMapper;

	@Override
	public void deleteErcodeByIds(Long[] ids) {
        ercodeMapper.deleteErcodeByIds(ids);
	}

    @Override
    @Cacheable(cacheNames = "ercode", key = "'ercode'")
    public List<Ercode> listErcode() {
        return ercodeMapper.listErcode();
    }

    @Override
    @CacheEvict(cacheNames = "ercode", key = "'ercode'")
    public void removeErcodeCache() {
    }

    @Override
    public Ercode getByTitle(String title) {
        Map<String,Object> cond = new HashMap<>();
        cond.put("title",title);
        List<Ercode> ercodes = ercodeMapper.selectByMap(cond);

        if(CollectionUtils.isEmpty(ercodes)){
            return null;
        }
        return ercodes.get(0);
    }
}
